<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class invList extends Page
{
       public $JTInvList = null;
       public $Image2 = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $JTJavaScript1 = null;
       public $JTSiteTheme1 = null;
       public $imgAdd = null;
       public $Image1 = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }


       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function invListCreate($sender, $params)
       {
       if($_SESSION['isAdmin']!=1)
       {
       $this->imgAdd->setVisible(false);
       }

       if($_SESSION['isAdmin']==1)
       {
       $this->imgAdd->setVisible(true);
       }

       if($_SESSION['access_part']==1)
       {
       $this->imgAdd->setVisible(false);
       }

       if($_SESSION['access_part']==2)
       {
       $this->imgAdd->setVisible(true);
       }

       $this->imgAdd->setLink('inventory_create.php');

       }

       function JTInvListShow($sender, $params)
       {
       $query1 = "select * from invstocks_tbl where company_id='".$_SESSION['company_id']."' and (type like '%".$this->edtSearch->Text."%'
       or stock_num like '%".$this->edtSearch->Text."%'
       or part_num like '%".$this->edtSearch->Text."%'
       or qty_available like '%".$this->edtSearch->Text."%'
       or description like '%".$this->edtSearch->Text."%')order by stock_num ASC";
       $result = mysql_query($query1)or die(mysql_error());

        $arr = array();
        while($row = mysql_fetch_array($result))
          {
            $stock_id = $row['stock_id'];
            $stock_num = $row['stock_num'];

            $photo = "<div align='center'><a href=inventory_edit.php?stock_id=".$stock_id."><img src='".$row['photo']."' height='50px' width='50px' title='edit'></a></div>";

            $result_status = mysql_query("select * from invstocks_status_tbl where stock_id='".$stock_id."'");
            $row_stat = mysql_fetch_array($result_status);

            $low_stock = $row_stat['low_stock_pt'];
            $qty_available = $row_stat['qty_available'];


            if($qty_available<=$low_stock)
            {
            $img = "<img src='image/low_stock.png' title='WARNING! low stock point.'>";
            }

            if($qty_available=='' ||$low_stock=='')
            {
            $img = "";
            }


            $vendor = "<a href=inventory_edit.php?stock_id=".$stock_id.">".$row['stock_num']."</a>";

            if($_SESSION['access_part']==1)
            {
            $tools = "<a href=inventory_status.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>
            <a href=veh_parts_crossref_list.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/cross_ref.png' title='alternative parts' no border></a>";
            }
            if($_SESSION['access_part']==2)
            {
            $tools = "<a href=inventory_status.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>
            <a href=veh_parts_crossref_list.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/cross_ref.png' title='alternative parts' no border></a>
            <img onclick=js_deleteStock('".$stock_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
            }
            //<a href=inventory_adjust_create.php?stock_id=".$stock_id."&stock_num=".$stock_num."><img src='image/status.png' title='status' no border></a>


            if($_SESSION['isAdmin']==1)
            {
            $arr[] = array(
                        'Photo' => $photo,
                        'Stock No' => $row['stock_num'].'  '.$img,
                        'Description' => $row['description'],
                        'Type' => $row['type'],
                        'Qty Available' => $row['qty_available'],
                        'Tools' => $tools
                        );
            }

            if($_SESSION['isAdmin']!=1)
            {
            $arr[] = array(
                        'Photo' => $photo,
                        'Stock No' => $row['stock_num'].'  '.$img,
                        'Description' => $row['description'],
                        'Type' => $row['type'],
                        'Qty Available' => $row['qty_available'],
                        'Tools' => $tools
                        );

            }


          }

            $this->JTInvList->setCellData($arr);


       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }

}

global $application;

global $invList;

//Creates the form
$invList=new invList($application);

//Read from resource file
$invList->loadResource(__FILE__);

//Shows the form
$invList->show();

?>